<template>
	<view class="page">
		<view class="group_2">
			<view class="d-flex flex-row align-center justify-center" style="height: 300rpx;background-color: #6a8cd9;">
				<view class="d-flex flex-column align-center justify-center">
					<view class="">
						<u-upload :fileList="fileList1" name="1" width="150rpx" height="150rpx" @afterRead="afterRead"
							@delete="deletePic" multiple :maxCount="1" />
					</view>
					<view class=""
						style="width: 160rpx;height: 50rpx;background: #d9ae2b;color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 25rpx;margin-right: 20rpx;line-height: 50rpx;">
						上传头像
					</view>
				</view>
			</view>

		</view>
		<view class="group_3">
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">姓名</text>
				<view class="item">
					<input type="text" placeholder="请输入姓名" class="atinput" v-model="nickname" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">性别</text>
				<view class="item">
					<view style="margin-top: 36rpx;">
						<u-radio-group v-model="insurance" @change="groupChange">
							<u-radio label="男" :name="1" activeColor="#ec652b" />
							<u-radio label="女" :name="2" customStyle="margin-left: 60rpx;" activeColor="#ec652b" />
						</u-radio-group>
					</view>
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">账号登录</text>
				<view class="item">
					<input type="number" placeholder="请输入手机号" class="atinput" v-model="userName" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">身份证号</text>
				<view class="item">
					<input type="idcard" placeholder="请输入身份证号" class="atinput" v-model="sfzhm" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">出生日期</text>
				<view class="item">
					<input type="text" placeholder="请选择出生日期" disabled v-model="datatime1" class="atinput"
						style="width: 400rpx;text-align: right;" @click="show1 = true" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">入职时间</text>
				<view class="item">
					<input type="text" placeholder="请选择入职时间 " disabled v-model="datatime2" class="atinput"
						style="width: 400rpx;text-align: right;" @click="show2 = true" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">年龄</text>
				<view class="item">
					<input type="text" placeholder="年龄" disabled v-model="age" class="atinput" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">邮箱</text>
				<view class="item">
					<input type="text" placeholder="请输入邮箱" class="atinput" v-model="email" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">账号手机号</text>
				<view class="item">
					<input type="text" placeholder="请输入密码" class="atinput" disabled v-model="userName" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;" v-if="status != 1">
				<text lines="1" class="text_8">登录密码</text>
				<view class="item">
					<input type="text" placeholder="请输入密码" class="atinput" v-model="password" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;" v-if="status != 1">
				<text lines="1" class="text_8">确认密码</text>
				<view class="item">
					<input type="text" placeholder="请输入确认密码" class="atinput" v-model="password2" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">员工内码</text>
				<view class="item">
					<input type="text" placeholder="请输入员工内码" class="atinput" v-model="user_code" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">最低折扣</text>
				<view class="item">
					<input type="text" placeholder="请输入最低折扣" class="atinput" v-model="discount_val" />
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between" style="align-items: center;">
				<text lines="1" class="text_8">所属部门</text>
				<view class="item">
					<view @tap="open" class="result-box">
						<text v-if="!firstItem.name">请选择</text>
						<text v-else-if="!secondItem.name">{{ firstItem.name }}</text>
						<text v-else-if="!thirdItem.name">{{ firstItem.name }} - {{ secondItem.name }}</text>
						<text v-else>{{ firstItem.name }} - {{ secondItem.name }} - {{ thirdItem.name }}</text>
					</view>
				</view>
			</view>

			<!-- <text lines="1" class="text_8">所属部门</text>
			<view class="item">
				<view class=" week-list">
					<view class="week-item" :class="{'active':index === selectId}" v-for="(item,index) in timeList"
						:key="index" @click="timesSelect(item,index)">
						{{item.venue_name}}
					</view>
				</view>
			</view> -->

			<text lines="1" class="text_8">所属角色</text>
			<view class="item">
				<view class=" week-list flex-wrap">
					<view class="week-item" :class="{'active': weekSelect.includes(item.id)}" v-for="item in weekList"
						:key="item.id" @click="handSelect(item)">
						{{ item.role_name }}
					</view>
					<!-- <view class="week-item active1" @click="selectAllWeeks">
						全选
					</view> -->
				</view>
			</view>
			<text lines="1" class="text_8">所属场馆</text>
			<view class="item">
				<view class=" week-list flex-wrap">
					<view class="week-item" :class="{'active': venuesSelect.includes(item.id)}"
						v-for="item in venuesList" :key="item.id" @click="handvenues(item)">
						{{ item.venue_name }}
					</view>
					<!-- <view class="week-item active1" @click="selectAllvenues">
						全选
					</view> -->
				</view>
			</view>
			<text lines="1" class="text_8" v-if="jiaoif == true">授权校区</text>
			<view class="item">
				<view class=" week-list flex-wrap">
					<view class="week-item" v-if="jiaoif == true" :class="{'active': SchoolSelect.includes(item.id)}"
						v-for="item in venueSchoollist" :key="item.id" @click="handSchool(item)">
						{{ item.venue_name }}
					</view>
					<!-- <view class="week-item active1" @click="selectAllvenues">
						全选
					</view> -->
				</view>
			</view>

			<text lines="1" class="text_8" v-if="jiaoif == true">授权教练</text>
			<view class="item" v-if="jiaoif == true">
				<view class=" week-list flex-wrap">
					<view class="week-item11" :class="{'active': jiaoSelect.includes(item.id)}" v-for="item in jiaoList"
						:key="item.id" @click="handjiao(item)">
						{{ item.full_name }}
					</view>
					<!-- <view class="week-item active1" @click="selectAlljiao">
						全选
					</view> -->
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between">
				<text lines="1" class="text_8">销售顾问</text>
				<view class="item">
					<u-checkbox shape='circle' :checked="reg_face1" @change='checkboxChange1'>选中</u-checkbox>
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between">
				<text lines="1" class="text_8">高级查询</text>
				<view class="item">
					<u-checkbox shape='circle' :checked="reg_face2" @change='checkboxChange2'>选中</u-checkbox>
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between">
				<text lines="1" class="text_8">会籍顾问</text>
				<view class="item">
					<u-checkbox shape='circle' :checked="reg_face3" @change='checkboxChange3'>选中</u-checkbox>
				</view>
			</view>
			<view class="d-flex flex-row justify-space-between">
				<text lines="1" class="text_8">同步教练库</text>
				<view class="item">
					<u-checkbox shape='circle' :checked="reg_face4" @change='checkboxChange4'>选中</u-checkbox>
				</view>
			</view>

			<text lines="1" class="text_8" v-if="projectsif == true">项目</text>
			<view class="item" v-if="projectsif == true">
				<view class="flex-space-between week-list flex-wrap">
					<view class="week-item11" :class="{'active':item.id == projectsId}"
						v-for="(item,index) in projectsList" :key="index" @click="projectsSelect(item,index)">
						{{item.name}}
					</view>
				</view>
			</view>

			<text lines="1" class="text_8">备注</text>
			<view class="item">
				<u-textarea v-model="remark" placeholder="请输入备注" maxlength='-1'></u-textarea>
			</view>

			<view class="" style="width: 100%;height: 10vh;">

			</view>
		</view>
		<!-- <button bindtap="onClick" class="button_3">
			保存
		</button> -->
		<view class="d-flex flex-row justify-space-between justify-center align-center"
			style="position: fixed;bottom: 0;height: 120rpx;background-color: #fff;width: 100%;padding: 0 8%;z-index: 99;">

			<view class="" @click="onClick"
				style="width: 100%;height: 80rpx;background: linear-gradient(0deg, rgba(214, 53, 53, 0.9), rgba(255, 64, 64, 0.93), rgba(250, 142, 142, 0.93));
				border-radius: 80rpx 80rpx;color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;">
				保存
			</view>
		</view>
		<u-datetime-picker :show="show1" v-model="value1" mode="date" @confirm="timelist1" :minDate="-845628841"
			:maxDate="2856778555000" @cancel="show1 = false"></u-datetime-picker>
		<u-datetime-picker :show="show2" v-model="value2" mode="date" @confirm="timelist2" :minDate="-845628841"
			:maxDate="2856778555000" @cancel="show2 = false"></u-datetime-picker>
		<u-popup :show="popupShow" @close="popupShow = false" type="bottom">
			<view class="popup-contents">
				<!-- <view class="popup-top" @tap="popupShow = false">关闭</view> -->

				<view class="data-contents">
					<!-- 左侧：大类导航 -->
					<scroll-view class="level1" scroll-y :scroll-into-view="firstScrollId" @scroll="handleFirstScroll">
						<view v-for="(item, index) in firstLevel" :key="item.id" :id="'first_' + item.id"
							style="margin-bottom: 20rpx;" :class="{ active: item.checked }"
							@tap="selectFirstLevel(item, index)">
							{{ item.name }}
						</view>
					</scroll-view>

					<!-- 中间：中类导航 -->
					<scroll-view v-show="firstItem.children && firstItem.children.length > 0" class="level2" scroll-y
						:scroll-into-view="secondScrollId" @scroll="handleSecondScroll">
						<view v-for="(item, index) in secondLevel" :key="item.id" :id="'second_' + item.id"
							style="margin-bottom: 20rpx;" :class="{ active: item.checked }"
							@tap="selectSecondLevel(item, index)">
							{{ item.name }}
						</view>
					</scroll-view>

					<!-- 右侧：子类内容 -->
					<scroll-view class="level3" scroll-y :scroll-into-view="thirdScrollId" @scroll="handleThirdScroll">
						<view v-for="(item, index) in thirdLevel" :key="item.id" :id="'third_' + item.id"
							style="margin-bottom: 20rpx;" :class="{ active: item.checked }"
							@tap="selectThirdLevel(item)">
							{{ item.name }}
						</view>
					</scroll-view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	function throttle(func, delay) {
		let timer = null;
		return function() {
			if (!timer) {
				func.apply(this, arguments);
				timer = setTimeout(() => {
					timer = null;
				}, delay);
			}
		};
	}
	const venues = require("@/api/venues/venues.js");
	export default {
		data() {
			return {
				fileList1: [],
				url_phone: '',
				fileList: [], //图片列表
				show: false,
				value1: Number(new Date()),
				showoccupation: false, //职业
				occupation_status: [], //职业
				showjineng: false, //技能等级
				jineng_status: [], //技能等级
				showchangguan: false, //所属场馆
				changguan_status: [], //所属场馆
				showxcx: false, //关联小程序
				xcx_status: [], //关联小程序
				occupation_list: [],
				jineng_list: [{
						id: 1,
						label: "LVO"
					},
					{
						id: 2,
						label: "LV1"
					},
					{
						id: 3,
						label: "LV2"
					},
					{
						id: 4,
						label: "LV3"
					},
					{
						id: 5,
						label: "LV4"
					},
				],
				changguan_list: [{
						id: 1,
						label: "苏州体育中心"
					},
					{
						id: 2,
						label: "扬州奥体"
					},
					{
						id: 3,
						label: "绍兴奥体"
					},
					{
						id: 4,
						label: "南通体育中心"
					},
				],
				xcx_list: [{
						id: 1,
						label: "衡阳奥星"
					},
					{
						id: 2,
						label: "衡阳奥星"
					},
					{
						id: 3,
						label: "苏州课代表"
					},
				],
				userInfo: {
					occupation_relation: '',
					occupation_relation_id: '',
					occupation_jineng: '',
					occupation_jineng_id: '',
					occupation_changguan: "",
					occupation_changguan_id: "",
					occupation_xcx: '',
					occupation_xcx_id: '',
					insurance: '',
				},
				mode: 'single', // 日历模式（默认日期选择）
				minDate: new Date('2025-01-01').getTime(), // 示例最小日期
				maxDate: new Date('2050-01-01').getTime(), // 示例最大日期
				show1: false,
				value1: Number(new Date()),
				datatime1: '',
				show2: false,
				value2: Number(new Date()),
				datatime2: '',
				weekList: [],
				weekSelect: [], //选中的
				timeList: [{
						name: '总部校区',
						id: '1'
					},
					{
						name: '南京校区',
						id: '2'
					},
					{
						name: '北京校区',
						id: '3'
					}
				],
				timeSelect: [], //选中的
				selectId: 0,
				venuesList: [],
				venuesSelect: [], //选中的
				jiaoList: [],
				jiaoSelect: [], //选中的
				value5: '',
				value3: false,
				popupShow: false,
				listData: [], // 原始三级数据

				// 三级数据缓存
				firstLevel: [], // 大类（pid=-1）
				secondLevel: [], // 中类（属于当前大类）
				thirdLevel: [], // 子类（属于当前中类）

				// 选中状态
				firstItem: {}, // 选中的大类
				secondItem: {}, // 选中的中类
				thirdItem: {}, // 选中的子类

				// 滚动位置
				firstScrollId: '',
				secondScrollId: '',
				thirdScrollId: '',
				nickname: '',
				insurance: '',
				userName: '',
				sfzhm: "",
				age: '',
				email: '',
				password: '',
				password2: "",
				user_code: '',
				discount_val: "",
				reg_face1: false,
				reg_face2: false,
				reg_face3: false,
				reg_face4: false,
				projectsList: [],
				projectsId: '',
				projectsif: false,
				bmid: '',
				pid: '',
				remark: '',
				auth_coachs: '',
				jiaoif: false,
				venueSchoollist: [],
				SchoolSelect: [],
				status: 2,
				id:''
			}
		},
		onLoad(options) {
			this.pid = options.pid
			this.status = options.status
			this.sysroleindex()
			this.department()
			this.venuevenues()

			if (options.status == 1) {
				const selectionArrs = JSON.parse(decodeURIComponent(options.selectionArr))
				this.selectionArrslist = selectionArrs
				console.log(this.selectionArrslist, 'this.selectionArrslist')
				this.url_phone = this.selectionArrslist.head_img
				this.fileList1.push({
					url: this.selectionArrslist.head_img
				});
				this.nickname = this.selectionArrslist.nickname
				this.insurance = this.selectionArrslist.sex
				this.userName = this.selectionArrslist.user_name
				this.sfzhm = this.selectionArrslist.sfzhm
				this.datatime1 = this.selectionArrslist.birth
				this.datatime2 = this.selectionArrslist.join_date
				this.age = this.selectionArrslist.age
				this.email = this.selectionArrslist.email
				this.user_code = this.selectionArrslist.user_code
				this.discount_val = this.selectionArrslist.discount_val
				this.id = this.selectionArrslist.id

				// 所属角色
				const strArray = this.selectionArrslist.role_id.trim().split(',');
				// 过滤掉空字符串，并将剩余的字符串转换为数字
				const numArray = strArray.filter(str => str).map(str => parseInt(str, 10));
				console.log(numArray);
				this.weekSelect = numArray
				// 所属场馆
				const strvenue_id = this.selectionArrslist.venue_id.trim().split(',');
				// 过滤掉空字符串，并将剩余的字符串转换为数字
				const numstrvenue_id = strvenue_id.filter(str => str).map(str => parseInt(str, 10));
				console.log(numstrvenue_id);
				this.venuesSelect = numstrvenue_id

				// 所属校区
				const strarea = this.selectionArrslist.area_ids.trim().split(',');
				// 过滤掉空字符串，并将剩余的字符串转换为数字
				const numstrarea = strarea.filter(str => str).map(str => parseInt(str, 10));
				console.log(numstrarea);
				this.SchoolSelect = numstrarea

				// 所属教练
				const strvcoachs = this.selectionArrslist.auth_coachs.trim().split(',');
				// 过滤掉空字符串，并将剩余的字符串转换为数字
				const numstrcoachs = strvcoachs.filter(str => str).map(str => parseInt(str, 10));
				console.log(numstrcoachs);
				this.jiaoSelect = numstrcoachs

				if (this.selectionArrslist.venue_id != '') {
					this.jiaoif = true
					this.venueSchool()
					this.venueCoach()
				}
				this.reg_face1 = this.selectionArrslist.is_coach == 1 ? true : false
				this.reg_face2 = this.selectionArrslist.senior == 1 ? true : false
				this.reg_face3 = this.selectionArrslist.is_consultant == 1 ? true : false
				this.reg_face4 = this.selectionArrslist.is_sync == 1 ? true : false

				if (this.selectionArrslist.is_sync == 1) {
					this.projectsif = true
					this.getVenueProjects()
					this.projectsId = this.selectionArrslist.venue_projects
				}
				this.remark = this.selectionArrslist.remark
				this.bmid = this.selectionArrslist.department
				
				const mini_depart = this.selectionArrslist.mini_depart
				const parts = mini_depart.split('/');
				
				
				if (parts.length >= 1) {
				    this.firstItem.name = parts[0];
				}
				if (parts.length >= 2) {
				    this.secondItem.name = parts[1];
				}
				if (parts.length >= 3) {
				    this.thirdItem.name = parts[2];
				}
			} else {
				// this.shuju()
				// this.getDeptSchool()

			}

		},
		computed: {
			// 过滤大类（pid=-1）
			filteredFirstLevel() {
				return this.listData.filter(item => item.pid === -1);
			}
		},
		mounted() {
			// 初始化数据（假设 listData 为三级嵌套结构）
			this.firstLevel = this.filteredFirstLevel;
			// if (this.firstLevel.length > 0) this.selectFirstLevel(this.firstLevel[0], 0);
		},
		methods: {
			projectsSelect(item, index) {
				this.projectsId = item.id
			},
			checkboxChange1(event) {
				console.log('复选框的值发生变化：', event);
				this.reg_face1 = event;
			},
			checkboxChange2(event) {
				console.log('复选框的值发生变化：', event);
				this.reg_face2 = event;
			},
			checkboxChange3(event) {
				console.log('复选框的值发生变化：', event);
				this.reg_face3 = event;
			},
			checkboxChange4(event) {
				console.log('复选框的值发生变化：', event);
				this.reg_face4 = event;
				if (this.reg_face4 == true) {
					this.projectsif = true
					this.getVenueProjects()
				} else {
					this.projectsif = false
					this.projectsList = []
				}
			},
			async getVenueProjects() {
				let params = {};
				let res = await venues.getVenueProjects(params);
				if (res.code == 1) {
					this.projectsList = res.data
				}
			},
			async onClick() {
				let params = {
					age: this.age,
					auth_coachs: this.auth_coachs,
					birth: this.datatime1,
					confirm_password: this.password2,
					department: this.bmid,
					discount_val: this.discount_val,
					head_img: this.url_phone,
					// is_applyer: 0,
					// is_auditor: 0,
					is_coach: this.reg_face1 ? 1 : 0,
					is_consultant: this.reg_face3 ? 1 : 0,
					// is_copyer: 0,
					is_sync: this.reg_face4 ? 1 : 0,
					join_date: this.datatime2,
					nickname: this.nickname,
					pass_word: this.password,
					role_id: this.weekSelect.toString(),
					senior: this.reg_face2 ? 1 : 0,
					sex: this.insurance,
					sfzhm: this.sfzhm,
					user_code: this.user_code,
					user_name: this.userName,
					venue_id: this.pid,
					venue_projects: this.projectsId,
					email: this.email,
					remark: this.remark,
					venue_ids: this.SchoolSelect.toString(),
					id:this.id
				};
				console.log(params, 'params')

				let res = await venues.usersave(params);
				if (res.code == 1) {
					uni.showToast({
						title: res.info,
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateBack({
							delta: 1 // 返回上一页面，如果页面栈中只有一个页面则该方法不会生效
						});
					}, 1000)
				} else {
					uni.showToast({
						title: res.info,
						icon: 'none'
					})
				}
			},

			open() {
				this.popupShow = true;
			},

			selectFirstLevel(item, index) {
				if (item.checked) {
					// 如果已经选中，取消选中
					item.checked = false;
					this.firstItem = {};
					this.secondLevel = [];
					this.thirdLevel = [];
					this.secondItem = {};
					this.thirdItem = {};
					this.firstScrollId = '';
					this.secondScrollId = '';
					this.thirdScrollId = '';
					this.bmid = null;
				} else {
					// 如果未选中，选中并更新相关数据
					this.firstLevel.forEach(i => i.checked = false);
					this.secondLevel.forEach(i => i.checked = false);
					this.thirdLevel.forEach(i => i.checked = false);
					this.thirdLevel = [];
					item.checked = true;
					this.firstItem = item;
					this.secondLevel = item.children || [];
					this.firstScrollId = `first_${item.id}`;
					this.secondScrollId = '';
					this.thirdScrollId = '';
					this.bmid = this.firstItem.id;
				}
				console.log('当前选中的一级 ID:', this.bmid);
			},

			selectSecondLevel(item, index) {
				if (item.checked) {
					// 如果已经选中，取消选中
					item.checked = false;
					this.secondItem = {};
					this.thirdLevel = [];
					this.thirdItem = {};
					this.secondScrollId = '';
					this.thirdScrollId = '';
					this.bmid = this.firstItem.id;
				} else {
					// 如果未选中，选中并更新相关数据
					this.secondLevel.forEach(i => i.checked = false);
					this.thirdLevel.forEach(i => i.checked = false);
					this.thirdLevel = [];
					item.checked = true;
					this.secondItem = item;
					this.thirdLevel = item.children || [];
					this.secondScrollId = `second_${item.id}`;
					this.thirdScrollId = '';
					this.bmid = this.secondItem.id;
				}
				console.log('当前选中的二级 ID:', this.bmid);
			},

			selectThirdLevel(item) {
				if (item.checked) {
					// 如果已经选中，取消选中
					item.checked = false;
					this.thirdItem = {};
					this.bmid = this.secondItem.id || this.firstItem.id;
				} else {
					// 如果未选中，选中
					this.thirdLevel.forEach(i => i.checked = false);
					item.checked = true;
					this.thirdItem = item;
					this.bmid = this.thirdItem.id;
				}
				console.log('当前选中的三级 ID:', this.bmid);
			},

			handleFirstScroll(e) {
				const scrollTop = e.detail.scrollTop;
				const items = this.firstLevel;
				for (let i = 0; i < items.length; i++) {
					const view = uni.createSelectorQuery().in(this).select(`#first_${items[i].id}`);
					view.boundingClientRect(data => {
						if (scrollTop >= data.top - 40 && scrollTop < data.bottom - 40) {
							this.selectFirstLevel(items[i], i);
						}
					}).exec();
				}
			},

			handleSecondScroll(e) {
				const scrollTop = e.detail.scrollTop;
				const items = this.secondLevel;
				for (let i = 0; i < items.length; i++) {
					const view = uni.createSelectorQuery().in(this).select(`#second_${items[i].id}`);
					view.boundingClientRect(data => {
						if (scrollTop >= data.top - 40 && scrollTop < data.bottom - 40) {
							this.selectSecondLevel(items[i], i);
						}
					}).exec();
				}
			},

			handleThirdScroll(e) {
				const scrollTop = e.detail.scrollTop;
				const items = this.thirdLevel;
				for (let i = 0; i < items.length; i++) {
					const view = uni.createSelectorQuery().in(this).select(`#third_${items[i].id}`);
					view.boundingClientRect(data => {
						if (scrollTop >= data.top - 40 && scrollTop < data.bottom - 40) {
							this.selectThirdLevel(items[i]);
						}
					}).exec();
				}
			},
			// 处理关闭弹出层事件
			handleClose() {
				this.popupShow = false;
			},

			// 处理 u-popup 的关闭事件
			handlePopupClose() {
				this.popupShow = false;
			},

			async sysroleindex() {
				let params = {};
				let res = await venues.sysroleindex(params);
				if (res.code == 1) {
					this.weekList = res.data.data
				}
			},
			async department() {
				let params = {
					pid: '-1',
					project_id: uni.getStorageSync("project_id")
				};
				let res = await venues.department(params);
				if (res.code == 1) {
					this.listData = res.data
				}
			},
			async venuevenues() {
				let params = {};
				let res = await venues.venuevenues(params);
				if (res.code == 1) {
					this.venuesList = res.data
				}
			},
			async venueCoach() {
				let params = {
					venue_ids: this.venuesSelect
				};
				let res = await venues.venueCoach(params);
				if (res.code == 1) {
					this.jiaoList = res.data
				}
			},
			moneychange(e) {},

			// async getDeptSchool() {
			// 	let params = {};
			// 	let res = await venues.getDeptSchool(params);
			// 	if (res.code === 1) {
			// 		this.venueSchoollist = res.data
			// 	}
			// },

			async venueSchool() {
				let params = {
					venue_ids: this.venuesSelect
				};
				let res = await venues.venueSchool(params);
				if (res.code == 1) {
					this.venueSchoollist = res.data
				}
			},
			// 新增的全选方法
			selectAlljiao() {
				if (this.jiaoSelect.length == this.jiaoList.length) {
					// 如果已全选，则清空选中数组
					this.jiaoSelect = [];
				} else {
					// 如果未全选，则选中所有项目
					this.jiaoSelect = this.jiaoList.map(item => item.id);
				}
			},
			handjiao(item) {
				let data = item.id;
				// 使用indexOf检查是否已选中，避免重复或遗漏
				const index = this.jiaoSelect.indexOf(data);
				if (index > -1) {
					// 如果已选中，则移除
					this.jiaoSelect.splice(index, 1);
				} else {
					// 如果未选中，则添加
					this.jiaoSelect.push(data);
				}
				const result = this.jiaoSelect.map(id => {
					const coach = this.jiaoList.find(c => c.id == id);
					if (coach) {
						return `${coach.venue_id}-${coach.id}`;
					}
					return null; // 如果没找到对应的对象，可以选择返回null或其他标识
				}).filter(Boolean).join(',');
				this.auth_coachs = result
				console.log(result);
			},
			// 新增的全选方法
			selectAllvenues() {
				if (this.venuesSelect.length == this.venuesList.length) {
					// 如果已全选，则清空选中数组
					this.venuesSelect = [];
				} else {
					// 如果未全选，则选中所有项目
					this.venuesSelect = this.venuesList.map(item => item.id);
				}
			},
			handvenues(item) {
				let data = item.id;
				// 使用indexOf检查是否已选中，避免重复或遗漏
				const index = this.venuesSelect.indexOf(data);
				if (index > -1) {
					// 如果已选中，则移除
					this.venuesSelect.splice(index, 1);
				} else {
					// 如果未选中，则添加
					this.venuesSelect.push(data);
				}
				if (this.venuesSelect.length > 0) {
					this.venueCoach()
					this.venueSchool()
					this.jiaoif = true
				} else {
					this.jiaoList = []
					this.jiaoSelect = []
					this.venueSchoollist = []
					this.SchoolSelect = []
					this.auth_coachs = ''
					this.jiaoif = false
				}
			},
			handSchool(item) {
				let data = item.id;
				// 使用indexOf检查是否已选中，避免重复或遗漏
				const index = this.SchoolSelect.indexOf(data);
				if (index > -1) {
					// 如果已选中，则移除
					this.SchoolSelect.splice(index, 1);
				} else {
					// 如果未选中，则添加
					this.SchoolSelect.push(data);
				}

			},
			timesSelect(item, index) {
				this.selectId = index
			},
			// 新增的全选方法
			selectAllWeeks() {
				if (this.weekSelect.length == this.weekList.length) {
					// 如果已全选，则清空选中数组
					this.weekSelect = [];
				} else {
					// 如果未全选，则选中所有项目
					this.weekSelect = this.weekList.map(item => item.id);
				}
			},
			handSelect(item) {
				let data = item.id;
				// 使用indexOf检查是否已选中，避免重复或遗漏
				const index = this.weekSelect.indexOf(data);
				if (index > -1) {
					// 如果已选中，则移除
					this.weekSelect.splice(index, 1);
				} else {
					// 如果未选中，则添加
					this.weekSelect.push(data);
				}
				console.log(this.weekSelect, 'this.weekSelect')
			},
			shuju() {

				this.jineng_status.push(
					this.jineng_list
				)
				this.changguan_status.push(
					this.changguan_list
				)
				this.xcx_status.push(
					this.xcx_list
				)
			},
			// 职业
			addoccupation(e) {
				this.userInfo.occupation_relation = e.value[0].name
				this.userInfo.occupation_relation_id = e.value[0].id
				this.showoccupation = false
			},
			addjineng(e) {
				this.userInfo.occupation_jineng = e.value[0].label
				this.userInfo.occupation_jineng_id = e.value[0].id
				this.showjineng = false
			},
			addchangguan(e) {
				this.userInfo.occupation_changguan = e.value[0].label
				this.userInfo.occupation_changguan_id = e.value[0].id
				this.showchangguan = false
			},
			addxcx(e) {
				this.userInfo.occupation_xcx = e.value[0].label
				this.userInfo.occupation_xcx_id = e.value[0].id
				this.showxcx = false
			},
			groupChange(n) {
				this.userInfo.insurance = n
			},
			timelist1(value) {
				this.show1 = false
				let date = new Date(value.value);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				console.log(y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s)
				this.datatime1 = y + '-' + MM + '-' + d
				// 定义出生日期
				const birthDate = new Date(this.datatime1);

				// 获取当前日期
				const currentDate = new Date();

				// 计算年龄
				let age = currentDate.getFullYear() - birthDate.getFullYear();
				const monthDiff = currentDate.getMonth() - birthDate.getMonth();
				if (monthDiff < 0 || (monthDiff === 0 && currentDate.getDate() < birthDate.getDate())) {
					age--;
				}
				this.age = age
				console.log(`年龄是 ${age} 岁。`);
				return y + '-' + MM + '-' + d; //年月日
				return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s; //年月日时分秒
			},
			timelist2(value) {
				console.log(value, 'value')
				this.show2 = false
				let date = new Date(value.value);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				console.log(y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s)
				this.datatime2 = y + '-' + MM + '-' + d
				return y + '-' + MM + '-' + d; //年月日
				return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s; //年月日时分秒
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: this.url_phone
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'https://sass-test.doit10019.com/api/upload/uploadOneImage', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							// user: 'test',
							project_id: getApp().globalData.projectId,
							app_id: this.$https.weixinAppId,

						},
						success: (res) => {
							let result = JSON.parse(res.data);
							this.url_phone = result.data.url
							setTimeout(() => {
								resolve(this.url_phone)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		width: 100%;
		// height: 100vh;
		background-color: #EDF5F5;

		.group_3 {
			background-color: rgba(255, 255, 255, 1.000000);
			width: 710rpx;
			height: 100%;
			display: flex;
			flex-direction: column;
			margin: 20rpx 0 0 20rpx;

			.item {
				// padding: 29rpx 30rpx 30rpx;
				padding: 25rpx 30rpx 20rpx 30rpx;

				.atinput {
					// border: #EBECEE 1rpx solid;
					font-size: 24rpx;
					height: 60rpx;
					width: 100%;
					padding-left: 20rpx;
					width: 400rpx;
					text-align: right;
				}

				.item-title {
					color: rgb(153, 153, 153);
					font-size: 28rpx;
					font-weight: 500;
					margin-bottom: 20rpx;
				}

				.value {
					color: rgb(51, 51, 51);
					font-size: 28rpx;
					font-weight: 500;
				}

				.time-cell {
					color: rgb(51, 51, 51);
					font-size: 28rpx;
					font-weight: 500;
					justify-content: flex-start;

					.time {
						width: 49%;

						&:last-of-type {
							margin-left: 20rpx;
						}
					}
				}

				.week-list {
					// display: grid;
					// grid-template-columns: repeat(5, 1fr);
					// grid-gap: 20rpx;
					// position: relative;
					flex-direction: row;
					width: 650rpx;
					font-size: 24rpx;
					flex-wrap: wrap;
					display: flex;
					justify-content: space-between;

					.week-item {
						// padding: 15rpx 0;
						// background-color: rgb(243, 243, 243);
						// border-radius: 5rpx;
						// text-align: center;
						// color: rgb(51, 51, 51);
						// font-size: 24rpx;
						// font-weight: 500;
						// border: solid 2rpx transparent;
						// box-sizing: border-box;
						padding: 15rpx 0;
						background-color: rgb(243, 243, 243);
						border-radius: 5rpx;
						text-align: center;
						color: rgb(51, 51, 51);
						font-size: 24rpx;
						font-weight: 500;
						border: solid 2rpx transparent;
						box-sizing: border-box;
						padding: 6rpx 12rpx;
						margin-top: 20rpx;
						width: 48%;
						height: auto;
						line-height: 65rpx;
					}

					.week-item11 {
						// padding: 15rpx 0;
						// background-color: rgb(243, 243, 243);
						// border-radius: 5rpx;
						// text-align: center;
						// color: rgb(51, 51, 51);
						// font-size: 24rpx;
						// font-weight: 500;
						// border: solid 2rpx transparent;
						// box-sizing: border-box;
						padding: 15rpx 0;
						background-color: rgb(243, 243, 243);
						border-radius: 5rpx;
						text-align: center;
						color: rgb(51, 51, 51);
						font-size: 24rpx;
						font-weight: 500;
						border: solid 2rpx transparent;
						box-sizing: border-box;
						padding: 6rpx 12rpx;
						margin-top: 20rpx;
						width: 24%;
						height: auto;
						line-height: 40rpx;
					}

					.active {
						color: rgba(255, 98, 0, 1);
						background-color: rgba(255, 65, 5, 0.1);
						// border: solid 2rpx rgb(99, 93, 247);
						position: relative;

						// &:before {
						// 	display: block;
						// 	content: '';
						// 	position: absolute;
						// 	width: 27rpx;
						// 	height: 28rpx;
						// 	right: -2rpx;
						// 	bottom: -2rpx;
						// 	background-image: url("https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/46b1cc85fcb0fd76095daf823b7d2bb4a3235519.png");
						// 	background-repeat: no-repeat;
						// 	background-size: 100%;
						// }
					}

					.active1 {
						color: rgba(255, 98, 0, 1);
						background-color: rgba(255, 65, 5, 0.1);
						// border: solid 2rpx rgb(99, 93, 247);
						position: relative;
					}

					.active2 {
						color: rgba(255, 98, 0, 1);
						background-color: rgba(255, 65, 5, 0.1);
						// border: solid 2rpx rgb(99, 93, 247);
						position: relative;
					}

					.check {
						color: rgb(51, 51, 51);
						font-size: 24rpx;
						position: absolute;
						bottom: 10rpx;
						right: 0;
					}
				}
			}
		}

		.text_2 {
			width: 93rpx;
			height: 23rpx;
			overflow-wrap: break-word;
			color: rgba(136, 136, 136, 1);
			font-size: 24rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 15rpx 0 0 21rpx;
		}

		.section_2 {
			background-color: rgba(229, 229, 229, 1.000000);
			width: 672rpx;
			height: 1rpx;
			display: flex;
			flex-direction: column;
			margin: 40rpx 0 0 18rpx;
		}

		.text_3 {
			width: 47rpx;
			height: 23rpx;
			overflow-wrap: break-word;
			color: rgba(136, 136, 136, 1);
			font-size: 24rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 42rpx 0 0 19rpx;
		}

		.text_4 {
			width: 82rpx;
			height: 26rpx;
			overflow-wrap: break-word;
			color: rgba(51, 51, 51, 1);
			font-size: 28rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 24rpx 0 0 20rpx;
		}

		.section_3 {
			background-color: rgba(229, 229, 229, 1.000000);
			width: 672rpx;
			height: 1rpx;
			display: flex;
			flex-direction: column;
			margin: 40rpx 0 0 18rpx;
		}

		.text_5 {
			width: 47rpx;
			height: 23rpx;
			overflow-wrap: break-word;
			color: rgba(136, 136, 136, 1);
			font-size: 24rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 39rpx 0 0 19rpx;
		}

		.text_6 {
			width: 82rpx;
			height: 26rpx;
			overflow-wrap: break-word;
			color: rgba(51, 51, 51, 1);
			font-size: 28rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 24rpx 0 0 20rpx;
		}

		.section_4 {
			background-color: rgba(229, 229, 229, 1.000000);
			width: 672rpx;
			height: 1rpx;
			display: flex;
			flex-direction: column;
			margin: 40rpx 0 0 18rpx;
		}

		.text_7 {
			width: 95rpx;
			height: 23rpx;
			overflow-wrap: break-word;
			color: rgba(136, 136, 136, 1);
			font-size: 24rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 39rpx 0 0 19rpx;
		}

		.image_2 {
			width: 151rpx;
			height: 151rpx;
			margin: 25rpx 0 0 18rpx;
		}


		.text_8 {
			width: 95rpx;
			height: 23rpx;
			overflow-wrap: break-word;
			color: rgba(136, 136, 136, 1);
			font-size: 24rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 0 0 0 20rpx;
		}

		.section_6 {
			width: 378rpx;
			height: 62rpx;
			flex-direction: row;
			display: flex;
			justify-content: space-between;
			margin: 26rpx 0 27rpx 21rpx;
		}

		.button_1 {
			background-color: rgba(243, 243, 243, 1.000000);
			height: 62rpx;
			display: flex;
			flex-direction: column;
			width: 174rpx;
		}

		.text_9 {
			width: 48rpx;
			height: 24rpx;
			overflow-wrap: break-word;
			color: rgba(51, 51, 51, 1);
			font-size: 24rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 19rpx 0 0 63rpx;
		}

		.button_2 {
			background-color: rgba(255, 65, 5, 0.100000);
			height: 62rpx;
			display: flex;
			flex-direction: column;
			width: 174rpx;
		}

		.text_10 {
			width: 73rpx;
			height: 24rpx;
			overflow-wrap: break-word;
			color: rgba(255, 98, 0, 1);
			font-size: 24rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 34rpx;
			margin: 19rpx 0 0 51rpx;
		}

		.button_3 {
			width: 90%;
			height: 80rpx;
			position: fixed;
			bottom: 20rpx;
			background: linear-gradient(0deg, rgba(214, 53, 53, 0.9), rgba(255, 64, 64, 0.93), rgba(250, 142, 142, 0.93));
			border-radius: 80rpx 80rpx;
			margin-left: 5%;
			color: #fff;
			font-size: 28rpx;
			z-index: 999;
		}
	}

	/* 适配 u-popup 样式 */
	.result-box {
		// width: 100%;
		// height: 40px;
		// line-height: 40px;
		// border: 1rpx solid #e4e7ed;
		// border-radius: 4rpx;
		// padding: 0 12px;
		// background-color: #fff;
		// font-size: 14px;
		// color: #666;
		font-size: 24rpx;
		height: 60rpx;
		width: 100%;
		padding-left: 20rpx;
		width: 400rpx;
		text-align: right;
		color: #888888;
		line-height: 60rpx;

		.placeHolder {
			color: #dcdfe6;
		}
	}

	.popup-contents {
		padding: 20px 0;
		border-radius: 12px 12px 0 0;

		.data-contents {
			display: flex;
			justify-content: space-between;
			height: calc(100vh - 200px);
			/* 自适应高度 */
			margin-top: 10px;
		}
	}

	.tabs {
		width: 80px;
		flex-shrink: 0;
		margin-right: 15px;

		.tabItem {
			padding: 8px 12px;
			margin-bottom: 10px;
			text-align: center;
			border-radius: 4rpx;

			&.tabItemActive {
				background-color: #f0f4ff;
				border-left: 2px solid #409eff;
				color: #409eff;
			}
		}
	}

	.result-box {
		// height: 40px;
		// line-height: 40px;
		// padding: 0 12px;
		// border: 1px solid #e4e7ed;
		// cursor: pointer;
	}

	.popup-contents {
		padding: 20px;
		background-color: #fff;
		height: 50vh;
	}

	.data-contents {
		display: flex;
		height: 100%;
	}

	.level1 {
		flex: 0 0 100px;
		border-right: 1px solid #e4e7ed;
		padding-right: 15px;

		.active {
			color: #409eff;
			font-weight: 500;
		}
	}

	.level2 {
		flex: 0 0 120px;
		border-right: 1px solid #e4e7ed;
		padding: 0 15px;

		.active {
			color: #409eff;
			font-weight: 500;
		}
	}

	.level3 {
		flex: 1;
		padding-left: 15px;

		.active {
			color: #409eff;
			font-weight: 500;
		}
	}
</style>